Skip to content

Conversation

jtschuster
Copy link
Member

Fixes #120394

  • Mark TypeMapAssemblyTargetAttributes when its TypeMapUniverse is marked
  • Recurse through TypeMapAssemblyTarget assemblies to find all TypeMapAttributes
  • Refactor TypeMapHandler construction and initialization
  • Use TypeReferenceEqualityComparer for Dictionaries
  • Mark TypeMap attribute origin / assembly when a TypeMap attribute is marked. Otherwise, assemblies with only TypeMapAttributes will not be kept.
  • Add more test coverage

- Mark TypeMapAssemblyTargetAttributes when a typemapuniverse is marked
- Recurse through TypeMapAssemblyTarget assemblies to find all TypeMapAttributes
- Refactor TypeMapHandler construction and initialization
- Use TypeReferenceEqualityComparer for Dictionaries
- Add more test coverage
@Copilot Copilot AI review requested due to automatic review settings October 7, 2025 18:31
@github-actions github-actions bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Oct 7, 2025
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Oct 7, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates TypeMap attribute handling in the IL linker to fix issues with assembly preservation and attribute marking. The changes improve how TypeMapAttributes are handled across assemblies and ensure assemblies containing only TypeMap attributes are properly preserved.

Key changes:

  • Enhanced TypeMapHandler to recursively process TypeMapAssemblyTarget assemblies
  • Improved attribute marking logic to mark assemblies when TypeMap attributes need to be preserved
  • Added comprehensive test coverage for cross-assembly TypeMap scenarios

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/tools/illink/test/Mono.Linker.Tests.Cases/Reflection/TypeMap.cs Extended test case with cross-assembly TypeMap scenarios and dependency validation
src/tools/illink/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/TypeMapSecondOrderReference.cs New test dependency assembly with TypeMap attributes for second-order reference testing
src/tools/illink/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/TypeMapReferencedAssembly.cs New test dependency assembly with TypeMap attributes for primary reference testing
src/tools/illink/src/linker/Linker/TypeReferenceEqualityComparer.cs Added obsolete marker for Default property to prevent misuse
src/tools/illink/src/linker/Linker/TypeMapHandler.cs Major refactor of TypeMapHandler with improved initialization, recursive assembly processing, and proper assembly marking
src/tools/illink/src/linker/Linker.Steps/SweepStep.cs Updated IsMarkedAssembly to check both assembly and main module marking
src/tools/illink/src/linker/Linker.Steps/MarkStep.cs Simplified TypeMapHandler initialization and made MarkAssembly method public

Copy link
Contributor

Tagging subscribers to this area: @dotnet/illink
See info in area-owners.md if you want to be subscribed.

@Sergio0694
Copy link
Contributor

@jkoritzinsky does this need to be backported to .NET 10? As in, I assume this bug would break CsWinRT 3.0 too? 🤔

@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 11.0.0 milestone Oct 8, 2025
@AaronRobinsonMSFT
Copy link
Member

@jkoritzinsky does this need to be backported to .NET 10? As in, I assume this bug would break CsWinRT 3.0 too? 🤔

Yes, we should get this backported into .NET 10 for the first servicing release.

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jtschuster jtschuster enabled auto-merge (squash) October 15, 2025 16:45
@jtschuster jtschuster merged commit 53110aa into dotnet:main Oct 15, 2025
75 of 77 checks passed
@github-project-automation github-project-automation bot moved this to Done in AppModel Oct 15, 2025
@AaronRobinsonMSFT
Copy link
Member

@jtschuster Let's make sure we a backport started when the .NET 10 staging branch is open.

@Sergio0694 If this is something your team needs, please remind us in early November so it doesn't get missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Trimmer doesn't keep TypeMapAssemblyTargetAttributes

4 participants